
#include <stdint.h>
#include "sec_delay.h"

void Delay_Set(DELAY *dly, uint16_t sec)
{
	dly->ticks = 0;
	dly->limit = sec;
	dly->limit*= 10;
	dly->state = 0;
	dly->over = 0;
}

void Delay_Start(DELAY *dly)
{	
	if(!dly->start)
	{
		//dly->ticks= 0;
		dly->start = 1;
		dly->state = 0;
	}
}

void Delay_Pause(DELAY *dly)
{
	dly->start = 0;
}

void Delay_Resume(DELAY *dly)
{
	dly->start = 1;
}

void Delay_Stop(DELAY *dly)
{
	dly->start = 0;
	dly->state = 0;
	dly->ticks = 0;
}

void Delay_Restart(DELAY *dly)
{
	dly->ticks = 0;
	dly->state = 0;
}

void Delay_Check(DELAY *dly)
{
	if(dly->start)
	{
		dly->ticks++;
	}
	if(dly->ticks >= dly->limit && dly->limit && dly->start)
	{
		dly->ticks = dly->limit;
		dly->state = 1;
	}
	else
	{
		dly->state = 0;
	}
}


